<template>

	<view class="store-collection">
		<view class="head_type">
			<text class="type" @click="onChangeActive(1)" :class="{'is-active':isActive == 1}">店铺收藏</text>
			<text class="type" @click="onChangeActive(2)" :class="{'is-active':isActive == 2}">商品收藏</text>
		</view>

		<view v-if="isActive == 1">
			<view class="modle_border" v-if="list.length>0">
				<view class="merchantList_list">
					<view class="merchantList_item" v-for="item in list" :key="item.id"
						@click="toMerchantDetails(item.id)">
						<view class="item_left">
							<image class="image" :src="item.shop_image" mode=""></image>
							<view class="content">
								<text class="title">{{item.shop_name}}</text>
								<view class="sunui_star">
									<view class="sunui_star_content">
										<SunuiStar :starSize='"0.5em"' :defaultStar="3" :disabledStar="true" />
									</view>
									<text class="sunui_star_txt">4.5</text>
								</view>
								<text class="sales">月销{{item.sold_count}}</text>
								<text class="sales" style="margin-top: 30upx;">厂家批发价 超便宜</text>
							</view>
						</view>
						<button class="item_right" type="default">进店</button>
					</view>
				</view>
			</view>
			<block v-else>
				<view>
					<block data-type="template" data-is="title" data-attr="title:'暂无收藏数据'">
						<view class="zanwushuju_border">
							<image class="zanwushuju_border_img" src="/static/pages/image/none_message.png"></image>
							<view class="zanwushuju_border_title">{{'暂无收藏数据'}}</view>
						</view>
					</block>
				</view>
			</block>
		</view>

		<view v-if="isActive == 2">
			<view class="modle_border" v-if="list.length>0">
				<view class="commodity_list">
					<view class="commodity_item" v-for="item in list" :key="item.id" @click="toDetails(item.id)">
						<image class="item_img" :src="getImages(item.image)" mode=""></image>
						<view class="item_content">
							<text class="title">{{item.title}}</text>
							<view class="item_money">
								<text style="font-size: 28rpx;">¥</text>
								<text style="font-size: 35rpx;">{{item.sell_price}}</text>
							</view>
							<text class="sales">月销{{item.sold_count}}</text>
						</view>
						<button class="btn" type="default">立即抢购</button>
					</view>
				</view>
			</view>
			<block v-else>
				<view>
					<block data-type="template" data-is="title" data-attr="title:'暂无收藏数据'">
						<view class="zanwushuju_border">
							<image class="zanwushuju_border_img" src="/static/pages/image/none_message.png"></image>
							<view class="zanwushuju_border_title">{{'暂无收藏数据'}}</view>
						</view>
					</block>
				</view>
			</block>
		</view>

		<u-loadmore :status="status" v-if="list.length>0" />
	</view>


</template>

<script>
	var app = getApp()
	import SunuiStar from '@/components/sunui-star/sunui-star.vue'
	export default {
		components: {
			SunuiStar
		},
		data() {
			return {
				list: [],
				leftid: 1,
				isActive: 1,
				status: 'loadmore'
			};
		},

		components: {},
		props: {},
		onLoad: function(t) {
			this.getList()
		},
		onReachBottom: function() {},
		methods: {
			toMerchantDetails(id) {
				uni.navigateTo({
					url: '/pagesA/merchantDetails/merchantDetails?id=' + id
				})
			},
			// 详情
			toDetails(id) {
				uni.navigateTo({
					url: '/pagesA/productDetails/productDetails?id=' + id
				});
			},
			getImages(images) {
				let img = JSON.parse(images).shift()
				return img
			},
			getList() {
				if (this.isActive == 1) {
					this.getShopcollectList()
				} else {
					this.getFavoritesList()
				}
			},
			onReset() {
				this.status = 'loadmore'
				this.list = []
				this.leftid = 1
			},
			onChangeActive(type) {
				if (this.isActive == type) return
				this.isActive = type
				this.onReset()
				this.getList()
			},
			getFavoritesList() {
				app.globalData.util.request({
					url: "entry/wxapp/Api",
					data: {
						m: "monai_market",
						r: "goods.index.userFavoritesList",
						uid: uni.getStorageSync('uid'),
						leftid: this.leftid
					},
					success: e => {
						const list = e.data.data
						this.list = this.list.concat(list)
						this.status = list.length < 6 ? "nomore" : "loadmore"
						this.leftid += 1
					}
				});
			},
			getShopcollectList() {
				app.globalData.util.request({
					url: "entry/wxapp/Api",
					data: {
						m: "monai_market",
						r: "shop.index.shopcollectlist",
						uid: uni.getStorageSync('uid'),
						leftid: this.leftid
					},
					success: e => {
						const list = e.data.data
						this.list = this.list.concat(list)
						this.status = list.length < 6 ? "nomore" : "loadmore"
						this.leftid += 1
					}
				});
			},
			delcollection() {},
		}
	};
</script>
<style scoped>
	page {
		background: #f9f9f9;
	}

	.head_type {
		height: 100upx;
		display: flex;
		align-items: center;
		text-align: center;
	}

	.head_type .type {
		flex: 1;
	}

	.head_type .is-active {
		color: red;
	}

	.mengceng1 {
		background-color: rgba(0, 0, 0, 0.5);
		color: #fff;
		position: absolute;
		width: 180rpx;
		height: 180rpx;
		line-height: 180rpx;
		text-align: center;
	}

	.nones {
		display: none;
	}

	.modle_border {
		width: 100%;
		background: #fff;
	}

	.modle {
		width: 90%;
		margin-left: 5%;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		height: 180rpx;
		border-bottom: 1rpx solid #f0f0f0;
	}

	.modle_img {
		height: 180rpx;
		width: 180rpx;
		float: left;
	}

	.modle_name {
		font-size: 30rpx;
		color: #333333;
		padding-left: 25rpx;
		width: 470rpx;
		float: left;
	}

	.modle_chexing {
		font-size: 26rpx;
		color: #555555;
		margin-top: 15rpx;
		padding-left: 25rpx;
		line-height: 54rpx;
		width: 470rpx;
		float: left;
	}

	.modle_chexing_btn {
		background: #0AC2AE;
		width: 146rpx;
		height: 54rpx;
		text-align: center;
		line-height: 54rpx;
		float: right;
		font-size: 28rpx;
		color: #FFFFFF;
		border-radius: 10rpx;
	}

	.modle_price {
		font-size: 30rpx;
		color: #F75F5F;
		margin-top: 35rpx;
		font-weight: bold;
		padding-left: 25rpx;
		width: 470rpx;
		float: left;
	}
</style>


<style scoped lang="scss">
	.merchantList_list {
		box-sizing: border-box;

		.merchantList_item+.merchantList_item {
			margin-top: 16upx;
		}

		.merchantList_item {
			padding: 26upx 10upx 37upx 15upx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: #FFFFFF;
			border-radius: 30upx;

			.item_left {
				display: flex;
				flex: 1;

				.image {
					width: 241upx;
					height: 241upx;
					border-radius: 10upx;
					margin-right: 20upx;
				}

				.content {
					flex: 1;
					display: flex;
					flex-direction: column;
				}

				.sunui_star_content {
					width: 160upx;
				}

				.title {
					font-size: 32upx;
					font-weight: 800;
					color: #242424;
				}

				.sales {
					font-size: 22upx;
					font-weight: 500;
					color: #535353;
				}

				.sunui_star {
					display: flex;
					align-items: center;
					width: 100%;
					margin: 16upx 0 14upx 0;
				}

				.sunui_star_txt {
					font-size: 22upx;
					font-weight: 500;
					color: #535353;
					line-height: 22upx;
					margin-top: 5rpx;
				}
			}

			.item_right {
				margin: 0;
				width: 143upx;
				height: 64upx;
				background: linear-gradient(141deg, #0CD8C2, #0BC2AE);
				border-radius: 32upx;
				font-size: 30upx;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 64upx;
			}
		}
	}

	.commodity_list {
		margin-top: 34upx;
		padding: 0 46upx 50upx 31upx;
		box-sizing: border-box;

		.commodity_item+.commodity_item {
			margin-top: 21upx;
		}

		.commodity_item {
			display: flex;
			position: relative;
			padding: 26upx 0 37upx 0;
			box-sizing: border-box;

			.item_img {
				width: 141upx;
				height: 141upx;
				border-radius: 10upx;
				margin-right: 14upx;
			}

			.item_content {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				flex: 1;
			}

			.title {
				font-size: 32upx;
				font-weight: 500;
				color: #242424;
			}

			.item_money {
				line-height: 28upx;
				font-weight: 500;
				color: #FF4E31;
			}

			.sales {
				font-size: 22upx;
				font-weight: 500;
				color: #535353;
			}

			.btn {
				position: absolute;
				right: 22upx;
				bottom: 43upx;
				width: 143upx;
				height: 64upx;
				line-height: 64upx;
				background: linear-gradient(141deg, #0CD8C2, #0BC2AE);
				border-radius: 32upx;
				font-size: 26upx;
				font-weight: 500;
				color: #FFFFFF;
				padding: 0;
				margin: 0;
			}
		}
	}
</style>
